package com.xliee.modules.sys.controller;

import com.xliee.modules.box.entity.BoxEntity;
import com.xliee.modules.box.service.IBoxService;
import com.xliee.modules.problem.entity.ProblemEntity;
import com.xliee.modules.problem.service.IProblemService;
import com.xliee.modules.sys.entity.UserEntity;
import com.xliee.modules.vehicle.entity.VehicleEntity;
import com.xliee.modules.vehicle.service.IVehicleService;
import jakarta.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import java.util.List;


@Controller
public class IndexController {

    @Autowired
    IBoxService boxService;

    @Autowired
    IProblemService problemService;

    @Autowired
    IVehicleService vehicleService;


    /**
     * 服务首页
     *
     * @param model
     * @return
     */
    @RequestMapping("/index")
    public String starter(HttpSession httpSession,Model model) {
        UserEntity user = (UserEntity) httpSession.getAttribute("ConstantUtil.SESSION_KEY");
        List<BoxEntity> boxList = boxService.getList();
        List<ProblemEntity> problemList = problemService.getIndexList();
        model.addAttribute("boxList", boxList);
        model.addAttribute("problemList", problemList);
        model.addAttribute("user",user);
        model.addAttribute("problem",new ProblemEntity());
        return "index";
    }

    /**
     * 检索提问问题用户
     * @param user
     * @param model
     * @return
     */
    @RequestMapping("/search")
    public String search(UserEntity user, Model model) {
        VehicleEntity vehicle = vehicleService.selectByUser(user);
        ProblemEntity problem = new ProblemEntity();
        if (vehicle != null) {
            problem.setImei(vehicle.getDrcId());
        }
        List<BoxEntity> boxList = boxService.getList();
        List<ProblemEntity> problemList = problemService.getIndexList();
        model.addAttribute("boxList", boxList);
        model.addAttribute("problemList", problemList);
        model.addAttribute("user",user);
        model.addAttribute("problem",problem);
        return "index";
    }



    @RequestMapping("/ui-buttons")
    public String buttons(Model model) {
        return "ui-buttons";
    }

    @RequestMapping("/ui-alerts")
    public String alerts(Model model) {
        return "ui-alerts";
    }

    @RequestMapping("/ui-card")
    public String card(Model model) {
        return "ui-card";
    }

    @RequestMapping("/ui-forms")
    public String forms(Model model) {
        return "ui-forms";
    }

    @RequestMapping("/ui-typography")
    public String typography(Model model) {
        return "ui-typography";
    }

    @RequestMapping("/register")
    public String register(Model model) {
        return "register";
    }

    @RequestMapping("/icon-tabler")
    public String tabler(Model model) {
        return "icon-tabler";
    }

    @RequestMapping("/sample-page")
    public String page(Model model) {
        return "sample-page";
    }

    @RequestMapping("/email")
    public String email(Model model) {
        return "email";
    }

    @RequestMapping("/math")
    public String math(Model model) {
        return "math";
    }

    @RequestMapping("/task/list")
    public String taskList(Model model) {
        return "task/listPage";
    }




}
